package com.gimi.cloud.bbp.commonService.order.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alipay.api.AlipayApiException;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.gimi.cloud.bbp.common.enums.CommonEnume;
import com.gimi.cloud.bbp.common.enums.CommonEnume.PayChannel;
import com.gimi.cloud.bbp.commonService.alipay.AliPayService;
import com.gimi.cloud.bbp.commonService.order.PayQueryService;
import com.gimi.cloud.bbp.dto.order.ShOrderPayinfoDTO;

@Service
public class PayQueryServiceImpl implements PayQueryService {
	
	@Autowired private AliPayService aliPayService;

	@Override
	public void orderQuery(ShOrderPayinfoDTO settlementInfo) {
		try {
			String opPayChannel = settlementInfo.getOpPayChannel();
			PayChannel payChannel = CommonEnume.PayChannel.valueOf(opPayChannel);
			switch (payChannel) {
			case ZFB:
				alipayQuery(settlementInfo.getOrderCode(),settlementInfo.getTrade_no());
				break;
			default:
				break;
			}
		} catch (Exception e) {
			// TODO: 查询异常 设置订单状态为待确认
		}
	}

	/**
	 * 支付宝订单支付状态查询
	 * @param orderCode
	 * @param trade_no
	 * @throws AlipayApiException
	 */
	private void alipayQuery(String orderCode, String trade_no) throws AlipayApiException {
		AlipayTradeQueryResponse alipayTradeQuery = aliPayService.alipayTradeQuery(orderCode,trade_no);
		// TODO: 处理支付结果
	}

}